<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <%@ include file="/static/admin/jsp/include.jsp"%>
    <script type="text/javascript">
        var id = "${id}";
        var submitForm = function($dialog, $grid, $pjq) {
            if ($('form').form('validate')) {
                var obj=sy.serializeObject($('form'));
                obj.img = $("#img").getFileId();
                obj.state = 2; //资讯

                if($("#type").combobox('getValue') == 1){
                    //内链跳转
                        obj.type = 1;
                    if($("#redType").combobox('getValue') == 0){
                        //内链跳转艺术家

                        obj.redType == 0;
                    }else{
                        //内链跳转艺术品
                        obj.redType == 1;
                    }
                        obj.targetContent = $("#targetContent").combobox('getValue');
                }else if($("#type").combobox('getValue') == 2){
                    //外链跳转
                        obj.type = 2;
                        obj.targetContent = $("#targetContentUrl").textbox('getValue');
                }
                console.log(obj);
                var url=sy.contextPath + '/banner/save';
                $.post(url, obj, function(result) {
                    if (result.code == 0) {
                        $grid.datagrid('reload');
                        $dialog.dialog('destroy');
                    } else {
                        $pjq.messager.e('保存失败,'+result.msg);
                    }
                }, 'json');
            }
        };

        $(function() {

            //初始化
            $("#targetContent").combobox({
                url:sy.contextPath+"/user/artList",
                valueField:'id',
                textField:'userName'
            });
            $("#out").hide();
            $("#type").combobox({
                onChange : function(n){
                    if(n == 1){
                        //内链
                        $("#in").show();
                        $("#out").hide();
                        $("#redirect_type").show();
                        $("#redType").combobox({
                            onChange : function(n){
                                console.log(n);
                                if(n == 0){
                                    //艺术家
                                    $("#targetContent").combobox({
                                        url:sy.contextPath+"/user/artList",
                                        valueField:'id',
                                        textField:'userName'
                                    });

                                }else if(n == 1){
                                    //作品
                                    $("#targetContent").combobox({
                                        url:sy.contextPath+"/goods/goodsList",
                                        valueField:'id',
                                        textField:'goodsName'
                                    });
                                }
                            }
                        });
                    }else if(n == 2){
                        //外链
                        $("#redirect_type").hide();
                        $("#out").show();
                        $("#in").hide();
                    }else{
                        //不跳转
                        $("#redirect_type").hide();
                        $("#out").hide();
                        $("#in").hide();
                    }
                }
            });

            $("#redType").combobox({
                onChange : function(n){
                    console.log(n);
                    if(n == 0){
                        //艺术家
                        $("#targetContent").combobox({
                            url:sy.contextPath+"/user/artList",
                            valueField:'id',
                            textField:'userName'
                        });

                    }else if(n == 1){
                        //作品
                        $("#targetContent").combobox({
                            url:sy.contextPath+"/goods/goodsList",
                            valueField:'id',
                            textField:'goodsName'
                        });
                    }
                }
            })



            if (id != '') {
                parent.$.messager.progress({
                    text : '数据加载中....'
                });
                $.post(sy.contextPath + '/banner/findById', {
                    id : id
                }, function(result) {
                    if (result) {
                        $('form').form('load', result);
                    }
                    console.log(result.goodsHeight)
                    $('#img').setFileId(result.img,true,1,true);

                    parent.$.messager.progress('close');
                }, 'json');
            }
        });


    </script>
</head>
<body>
<form id="form" method="post">
    <input name="id" type="hidden" />
    <div style="padding:15px;font-size: 12px">
        <table style="table-layout:fixed;" border="0" cellspacing="0" class="formtable">
            <tr>
                <th style="width:100px;">标题：</th>
                <td>
                    <input id="title" name="title" class="easyui-textbox" missingMessage="请输入" prompt="请输入" style="width:90%;"
                           data-options="required:true" />
                </td>
                <th style="width:100px;">描述：</th>
                <td>
                    <input id="info" name="info" class="easyui-textbox" missingMessage="请输入" prompt="请输入" style="width:90%;"
                           data-options="required:true" />
                </td>
            </tr>
            <tr>
                <th style="width:100px;">图片：</th>
                <td colspan="3">
                    <div id="img" multi="true" fileCountLimit="9" type="file" showImage="true" bestSize="640*320" fileType="jpg,png"
                         showWidth="40" showHeight="40" fileSize="2MB" buttonText="资讯图片" url="fileUpload"></div>
                </td>

            </tr>
            <tr>
                <th style="width:100px;">跳转方式：</th>
                <td colspan="3">
                    <select id="type" class="easyui-combobox" name="type" style="width:90%;" data-options="required:true,editable:false">
                        <option value="1">内链</option>
                        <option value="2">外链</option>
                        <option value="3">不跳转</option>
                    </select>
                </td>

            </tr>
            <tr   id="redirect_type">
                <th style="width:100px;">跳转类型：</th>
                <td colspan="3">
                    <select id="redType" class="easyui-combobox" name="redType" style="width:90%;" data-options="required:true,editable:false">
                        <option value="0">艺术家</option>
                        <option value="1">作品</option>
                    </select>
                </td>
            </tr>
            <tr id="in">
                <th style="width:100px;">目标：</th>
                <td colspan="3">
                    <input id="targetContent" class="easyui-combobox" style="width:90%;" name="targetContent" data-options="editable:false"/>
                </td>

            </tr>
            <tr id="out">
                <th style="width:100px;">外链地址：</th>
                <td colspan="3">
                    <input id="targetContentUrl" class="easyui-textbox" style="width:90%;" name="targetContent" data-options="editable:true"/>
                </td>

            </tr>
            <tr>
                <th style="width:100px;">排序：</th>
                <td colspan="3">
                    <input id="sortOrder" class="easyui-textbox" style="width:90%;" name="sortOrder" data-options="required:true"/>
                </td>
            </tr>
        </table>
    </div>
</form>
</body>
</html>